package liaocheng.shandong.latitude.caocuooo

import android.app.Activity
import android.os.Bundle
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import kotlinx.android.synthetic.main.activity_main.*
import liaocheng.shandong.latitude.viewtest.R

class MainActivity : Activity() {

    private val items= ArrayList<String>()

    private lateinit var srl: SwipeRefreshLayout
    private lateinit var recyclerview:RecyclerView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main);
        initView()
        initListener();
    }

    fun initView(){
        recyclerview=findViewById(R.id.recyclerview) as RecyclerView
        srl = findViewById(R.id.srl) as SwipeRefreshLayout;
        recyclerview.layoutManager= LinearLayoutManager(this) as RecyclerView.LayoutManager?
        recyclerview.addItemDecoration(DividerItemDecoration(this,android.support.v7.widget.DividerItemDecoration.VERTICAL))
        items.getData()
        recyclerview.adapter=RecyclerViewAdapter(items);
    }
    fun initListener(){
        srl.setOnRefreshListener {
           items.getData()
            recyclerview.adapter=RecyclerViewAdapter(items)
            srl.setRefreshing(false);
        }
    }

    fun ArrayList<String>.getData(){
        for (i in 0 until 10){
            this.add("星期"+i)
        }
    }
}
